home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / ixemlsrc.lha / ixemul / utils / functions.c < prev    next >
C/C++ Source or Header  |  1995-12-23  |  8KB  |  323 lines

  1. /*
  2.     Ixprefs v.2.1--ixemul.library configuration program
  3.     Copyright © 1995 Kriton Kyrimis
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <exec/types.h>
  22. #include <intuition/intuition.h>
  23. #include <proto/dos.h>
  24. #include <proto/intuition.h>
  25. #include "ixprefs.h"
  26. #include "ixemul.h"
  27. #include "version.h"
  28.  
  29. #define IXPREFS_VERSION "2.1"
  30.  
  31. #define RUNNING 1
  32. #define NOT_RUNNING 0
  33.  
  34. #define CONFIGFILE "ENVARC:" IX_ENV_SETTINGS
  35. #define ENVFILE "ENV:" IX_ENV_SETTINGS
  36.  
  37. /* These strings are long enough to have a high probability of being typed
  38.    incorrectly, especially as they are used more than once. Using these
  39.    definitions, we can detect typing errors at compile time */
  40. #define IX_NO_INSERT_DISK_REQUESTER "ix_no_insert_disk_requester"
  41. #define IX_UNIX_PATTERN_MATCHING_CASE_SENSITIVE "ix_unix_pattern_matching_case_sensitive"
  42. #define IX_WATCH_STACK "ix_watch_stack"
  43. #define IX_TRANSLATE_SLASH "ix_translate_slash"
  44. #define IX_MEMBUF_LIMIT "ix_membuf_limit"
  45. #define IX_RED_ZONE_SIZE "ix_red_zone_size"
  46. #define IX_FS_BUF_FACTOR "ix_fs_buf_factor"
  47. #define IX_ALLOW_AMIGA_WILDCARD "ix_allow_amiga_wildcard"
  48.  
  49. extern void showrequester(struct Window*, char *, char *);
  50.  
  51. extern struct ixemul_base *ixemulbase;
  52. extern int translateslash, membuf, watcher, redzone, blocks, cases, suppress,
  53.        amigawildcard, noflush, ignoreenv, networking;
  54.  
  55. struct ix_settings settings;
  56.  
  57. extern void displayprefs(void);
  58.  
  59. void
  60. use(void)
  61. {
  62.   FILE *f;
  63.   unsigned long new_flags;
  64.  
  65.   new_flags =
  66.     (translateslash ? ix_translate_slash : 0)
  67.   | (watcher ? ix_watch_stack : 0)
  68.   | (cases ? ix_unix_pattern_matching_case_sensitive : 0)
  69.   | (suppress ? ix_no_insert_disk_requester : 0)
  70.   | (amigawildcard ? ix_allow_amiga_wildcard : 0)
  71.   | (noflush ? ix_do_not_flush_library : 0)
  72.   | (ignoreenv ? ix_ignore_global_env : 0);
  73.   settings.version = IX_VERSION;
  74.   settings.revision = IX_REVISION;
  75.   settings.flags = new_flags;
  76.   settings.membuf_limit = membuf;
  77.   settings.red_zone_size = redzone;
  78.   settings.fs_buf_factor = blocks;
  79.   settings.network_type = networking;
  80.   ix_set_settings(&settings);
  81.   f = fopen(ENVFILE, "w");
  82.   if (f) {
  83.     fwrite(&settings, sizeof(settings), 1, f);
  84.     fclose(f);
  85.   } else {
  86.     showrequester(ixprefsWnd, "Can't open " ENVFILE, "OK");
  87.   }
  88. }
  89.  
  90. void
  91. save(void)
  92. {
  93.   FILE *f;
  94.  
  95.   use();
  96.   f = fopen(CONFIGFILE, "w");
  97.   if (f) {
  98.     fwrite(&settings, sizeof(settings), 1, f);
  99.     fclose(f);
  100.   }else{
  101.     showrequester(ixprefsWnd, "Can't open " CONFIGFILE, "OK");
  102.   }
  103. }
  104.  
  105. int
  106. selected(int which)
  107. {
  108.   if (ixprefsGadgets[which]->Flags & GFLG_SELECTED) {
  109.     return 1;
  110.   }else{
  111.     return 0;
  112.   }
  113. }
  114.  
  115. int savegadClicked( void )
  116. {
  117.   /* routine when gadget "Save" is clicked. */
  118.   save();
  119.   return NOT_RUNNING;
  120. }
  121.  
  122. int usegadClicked( void )
  123. {
  124.   /* routine when gadget "Use" is clicked. */
  125.   use();
  126.   return NOT_RUNNING;
  127. }
  128.  
  129. int cancelgadClicked( void )
  130. {
  131.   /* routine when gadget "Cancel" is clicked. */
  132.   return NOT_RUNNING;
  133. }
  134.  
  135. int translateslashClicked( void )
  136. {
  137.   /* routine when gadget "translate /" is clicked. */
  138.   translateslash = selected(GDX_translateslash);
  139.   return RUNNING;
  140. }
  141.  
  142. int membufClicked( void )
  143. {
  144.   /* routine when gadget "membuf size" is clicked. */
  145.   membuf = GetNumber(ixprefsGadgets[GDX_membuf]);
  146.   return RUNNING;
  147. }
  148.  
  149. int redzoneClicked( void )
  150. {
  151.   /* routine when gadget "red zone size" is clicked. */
  152.   redzone = GetNumber(ixprefsGadgets[GDX_redzone]);
  153.   return RUNNING;
  154. }
  155.  
  156. int watcherClicked( void )
  157. {
  158.   /* routine when gadget "enable stack watcher" is clicked. */
  159.   watcher = selected(GDX_watcher);
  160.   return RUNNING;
  161. }
  162.  
  163. int blocksClicked( void )
  164. {
  165.   /* routine when gadget "physical blocks to build one logical block (for stdio)" is clicked. */
  166.   blocks = GetNumber(ixprefsGadgets[GDX_blocks]);
  167.   return RUNNING;
  168. }
  169.  
  170. int caseClicked( void )
  171. {
  172.   /* routine when gadget "case sensitive)" is clicked. */
  173.   cases = selected(GDX_case);
  174.   return RUNNING;
  175. }
  176.  
  177. int suppressClicked( void )
  178. {
  179.   /* routine when gadget "suppress the \"Insert volume in drive\" requester" is clicked. */
  180.   suppress = selected(GDX_suppress);
  181.   return RUNNING;
  182. }
  183.  
  184. int networkingClicked( void )
  185. {
  186.   /* routine when cycle gadget "Networking support" is clicked. */
  187.   networking = ixprefsMsg.Code;
  188.   return RUNNING;
  189. }
  190.  
  191. int amigawildcardClicked( void )
  192. {
  193.   /* routine when gadget "allow Amiga wildcards" is clicked. */
  194.   amigawildcard = selected(GDX_amigawildcard);
  195.   return RUNNING;
  196. }
  197.  
  198. int noflushClicked( void )
  199. {
  200.   /* routine when gadget "do not flush library" is clicked. */
  201.   noflush = selected(GDX_noflush);
  202.   return RUNNING;
  203. }
  204.  
  205. int ignoreenvClicked( void )
  206. {
  207.   /* routine when gadget "ignore global environment (ENV:)" is clicked. */
  208.   ignoreenv = selected(GDX_ignoreenv);
  209.   return RUNNING;
  210. }
  211.  
  212. int ixprefssave( void )
  213. {
  214.   /* routine when (sub)item "Save" is selected. */
  215.   save();
  216.   return NOT_RUNNING;
  217. }
  218.  
  219. int ixprefsuse( void )
  220. {
  221.   /* routine when (sub)item "Use" is selected. */
  222.   use();
  223.   return NOT_RUNNING;
  224. }
  225.  
  226. int ixprefsabout( void )
  227. {
  228.   /* routine when (sub)item "About" is selected. */
  229.   showrequester(ixprefsWnd,
  230.     "Ixprefs v." IXPREFS_VERSION "--ixemul.library configuration program\n"
  231.     "Copyright \251 1995 Kriton Kyrimis\n\n"
  232.     "This program is free software; you can redistribute it\n"
  233.     "and/or modify it under the terms of the GNU General\n"
  234.     "Public License as published by the Free Software Foundation;\n"
  235.     "either version 2 of the License, or (at your option)\n"
  236.     "any later version.\n\n"
  237.     "GUI designed using GadToolsBox 2.0c by Jan van den Baard",
  238.     "OK");
  239.   return RUNNING;
  240. }
  241.  
  242. int ixprefsquit( void )
  243. {
  244.   /* routine when (sub)item "Quit" is selected. */
  245.   return NOT_RUNNING;
  246. }
  247.  
  248. void read_from_settings(struct ix_settings *settings)
  249. {
  250.   translateslash = (settings->flags & ix_translate_slash) != 0;
  251.   watcher = (settings->flags & ix_watch_stack) != 0;
  252.   cases = (settings->flags & ix_unix_pattern_matching_case_sensitive) != 0;
  253.   suppress = (settings->flags & ix_no_insert_disk_requester) != 0;
  254.   amigawildcard = (settings->flags & ix_allow_amiga_wildcard) != 0;
  255.   noflush = (settings->flags & ix_do_not_flush_library) != 0;
  256.   ignoreenv = (settings->flags & ix_ignore_global_env) != 0;
  257.   membuf = settings->membuf_limit;
  258.   redzone = settings->red_zone_size;
  259.   blocks = settings->fs_buf_factor;
  260.   networking = settings->network_type;
  261. }
  262.  
  263. void defaults(void)
  264. {
  265.   read_from_settings(ix_get_default_settings());
  266. }
  267.  
  268. int ixprefsreset(void)
  269. {
  270.   /* routine when (sub)item "Reset to defaults" is selected. */
  271.  
  272.   defaults();
  273.   displayprefs();
  274.   return RUNNING;
  275. }
  276.  
  277. int
  278. last_saved(void)
  279. {
  280.   FILE *f;
  281.   int status;
  282.  
  283.   f = fopen(CONFIGFILE, "r");
  284.   if (f) {
  285.     fread(&settings, sizeof(settings), 1, f);
  286.     fclose(f);
  287.     read_from_settings(&settings);
  288.     status = 0;
  289.   }else{
  290.     showrequester(ixprefsWnd, "Can't open " CONFIGFILE, "OK");
  291.     status = 1;
  292.   }
  293.   return status;
  294. }
  295.  
  296. int ixprefslast( void )
  297. {
  298.   /* routine when (sub)item "Last Saved" is selected. */
  299.   if (last_saved() == 0) {
  300.     displayprefs();
  301.   }
  302.   return RUNNING;
  303. }
  304.  
  305. int ixprefsrestore( void )
  306. {
  307.   struct ix_settings *settings;
  308.  
  309.   /* routine when (sub)item "Restore" is selected. */
  310.   settings = ix_get_settings();
  311.   read_from_settings(settings);
  312.  
  313.   displayprefs();
  314.  
  315.   return RUNNING;
  316. }
  317.  
  318. int ixprefsCloseWindow( void )
  319. {
  320.   /* routine for "IDCMP_CLOSEWINDOW". */
  321.   return NOT_RUNNING;
  322. }
  323.